fix: Allow non blocking all the way down to the instance level#27
fix: Allow non blocking all the way down to the instance level#27
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes blocking behavior in the NATS API server to allow non-blocking operation at the instance level. The changes enable running specs and other tasks without being blocked by worker threads sleeping.
- Adds a
blockingparameter throughout the worker spawn chain to control blocking behavior - Splits worker setup into blocking (
setup_worker!) and non-blocking (setup_worker) variants - Refactors parameter passing to use keyword arguments for better clarity
| return worker.setup_worker!(nats_url: url, service_opts: opts) if blocking | ||
|
|
||
| worker.setup_worker(nats_url: url, service_opts: opts) |
There was a problem hiding this comment.
The conditional logic is inverted. When blocking is true, the method calls setup_worker! which blocks with sleep, but then immediately returns, preventing the sleep from executing. This should be unless blocking or the logic should be restructured.
| return worker.setup_worker!(nats_url: url, service_opts: opts) if blocking | |
| worker.setup_worker(nats_url: url, service_opts: opts) | |
| if blocking | |
| worker.setup_worker!(nats_url: url, service_opts: opts) | |
| else | |
| worker.setup_worker(nats_url: url, service_opts: opts) | |
| end |
There was a problem hiding this comment.
I think it got this wrong. Not sure why it thinks the sleep is prevented from executing
| @client = NATS.connect url | ||
| @service = @client.services.add(**opts) | ||
| @client = NATS.connect nats_url | ||
| @service = @client.services.add(build_service_opts(service_opts:)) |
There was a problem hiding this comment.
The build_service_opts method call uses named parameter syntax but the method definition shows service_opts: parameter. This should be build_service_opts(service_opts: service_opts) for clarity.
| @service = @client.services.add(build_service_opts(service_opts:)) | |
| @service = @client.services.add(build_service_opts(service_opts: service_opts)) |
This allows running specs and any other tasks
that you want to accomplish without being blocked
by worker threads sleeping